home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 24.5 KB | 1,092 lines | [TEXT/R*ch] |
- /*
- File: TranscriptWindow.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __TRANSCRIPTWINDOW__
- #include "TranscriptWindow.h"
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __FONTS__
- #include "FONTS.h"
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __WRITELINEWINDOW__
- #include "WriteLineWindow.h"
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __LIMITS__
- #include <Limits.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __OBJECTLIST__
- #include "ObjectList.h"
- #endif
-
- /***********************************|****************************************/
-
- #pragma segment TranscriptWindow
-
- /***********************************|****************************************/
-
- DeclareList ( TTranscriptWindow, TTranscriptWindowList );
- ImplementList ( TTranscriptWindow, TTranscriptWindowList , true );
-
- /***********************************|****************************************/
-
- TTranscriptWindowList gTranscriptWindowList;
-
- /***********************************|****************************************/
-
- static VHSelect gOrthogonal[2] = { h, v };
-
- /***********************************|****************************************/
-
- static RgnHandle GetSaveVisRgn(void)
- {
- const long addr = 0x09F2;
-
- return * (RgnHandle *) addr;
- }
-
- /***********************************|****************************************/
-
- inline VHSelect LongerSide(Rect& r)
- {
- if ((r.bottom - r.top) >= (r.left - r.right))
- return v;
- else
- return h;
- }
-
- /***********************************|****************************************/
-
- typedef struct LogInfoRecord
- {
- Str31 fontName;
- short fontSize;
- short lines;
- short columns;
- } LogInfoRecord, *LogInfoRecordPtr, **LogInfoRecordHandle;
-
- /***********************************|****************************************/
-
- static short GetFontNumber ( StringPtr fontName )
- {
- short result;
-
- GetFNum ( fontName, & result );
-
- return result;
- }
-
- /***********************************|****************************************/
-
- TTranscriptWindow::TTranscriptWindow ( short windowID ) :
- fWindowResID ( windowID ),
- fDebugWindowPtr ( nil ),
- fText ( nil ),
- fLineLens ( nil ),
- fFirst ( 0 ),
- fLast ( 0 ),
- fPos ( 0 ),
- fHeigth ( 0 ),
- fARgn ( nil ),
-
- fGotRefNum ( false ),
- fRefNum ( 0 ),
- fVRefNum ( 0 ),
-
- fScrollWindowWhenTextIsAdded ( true ),
- fWrToWindow ( true ),
- fWrToFile ( false ),
-
- fDirty ( false )
- {
- // Get the information about the size of buffer for this window.
- LogInfoRecordHandle logInfoH = ( LogInfoRecordHandle ) GetResource ( 'LINF', windowID );
- if ( logInfoH )
- {
- fFaceInfo.tsFont = GetFontNumber ( (**logInfoH).fontName );
- fFaceInfo.tsFace = 0;
- fFaceInfo.tsSize = (**logInfoH).fontSize;
- fFaceInfo.tsColor.red = fFaceInfo.tsColor.green = fFaceInfo.tsColor.blue = 0;
- fLines = (**logInfoH).lines;
- fPerLine = (**logInfoH).columns;
- }
- else
- {
- fFaceInfo.tsFont = GetFontNumber ( "\pMonaco" );
- fFaceInfo.tsFace = 0;
- fFaceInfo.tsSize = 12;
- fFaceInfo.tsColor.red = fFaceInfo.tsColor.green = fFaceInfo.tsColor.blue = 0;
- fLines = 120;
- fPerLine = 80;
- }
-
- fTotal = fLines * fPerLine;
-
-
- fSBars [ v ] = fSBars [ h ] = nil;
-
- SetRect(&fStdDrag, 4, 24, qd.screenBits.bounds.right - 4, qd.screenBits.bounds.bottom - 4); //this is suggested in Inside Macintosh
- SetRect(&fStdSize, 20, 20, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom - 20); //arbitrary Minimum size; Maximum size is screen
-
- fViewSize.v = fViewSize.h = 0;
- fEndOfText.v = fEndOfText.h = 0;
-
- fText = (char **) NewHandleClear(fTotal);
- if (fText == NULL)
- {
- DebugStr ("\pNot enough memory to allocate the Debug Window''s Line Array: " );
- return ;
- }
-
- fLineLens = (short **) NewHandleClear ( fLines * sizeof ( (*fLineLens)[0] ) );
- if (fLineLens == NULL)
- {
- DisposeHandle(Handle(fText));
- DebugStr ("\pNot enough memory to allocate the Debug Window''s LineLen Array: ");
- return;
- }
-
- fLast = fTotal - fPerLine;
-
- gTranscriptWindowList.Append ( this );
- }
-
- /***********************************|****************************************/
-
- TTranscriptWindow::~TTranscriptWindow ( )
- {
- gTranscriptWindowList.Remove ( this );
- }
-
- /***********************************|****************************************/
-
- void SetResourceNoPurge ( OSType resType, short resID )
- {
- Handle h = GetResource ( resType, resID );
- if ( h )
- HNoPurge ( h );
- }
-
- /***********************************|****************************************/
-
- Boolean TTranscriptWindow::Initialize ( )
- {
-
- GrafPtr savePort;
-
- GetPort(&savePort);
- if ( fDebugWindowPtr == nil )
- { Rect bounds = { 40, 16, 40+12*36, 16+6*80+16 };
- Boolean goAway = true, visible = false;
-
- fDebugWindowPtr = GetNewWindow ( fWindowResID, nil, (WindowPtr) -1 );
- ((WindowPeek) fDebugWindowPtr)->refCon = (long) this;
- // fDebugWindowPtr = Neindow(nil, & bounds, "\p", visible, documentProc, (WindowPtr) -1, goAway, 0);
-
- #if 0
- Boolean RectOnScreen ( const Rect & rect );
- if ( ! RectOnScreen ( fDebugWindowPtr->portRect ) )
- {
- Rect r =
-
- }
- #endif
-
- SetRect(&fStdDrag, 4, 24, qd.screenBits.bounds.right - 4, qd.screenBits.bounds.bottom - 4); //this is suggested in Inside Macintosh
- SetRect(&fStdSize, 20, 20, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom - 20); //arbitrary Minimum size; Maximum size is screen
-
- fARgn = NewRgn();
-
- SetPt(&fEndOfText, kHMargin, (short) BaseLine(fLines));
-
- SetPort(fDebugWindowPtr);
-
- // Now, get the information about this font's width, etc.
- TextFont ( fFaceInfo.tsFont );
- TextSize ( fFaceInfo.tsSize );
- TextFace ( fFaceInfo.tsFace );
- GetFontInfo ( & fFontInfo );
- fHeigth = fFontInfo.ascent + fFontInfo.descent + fFontInfo.leading;
-
-
- fHeigth = fFontInfo.ascent + fFontInfo.descent + fFontInfo.leading;
- SetPt(&fViewSize, (2 * kHMargin) + (fPerLine * fFontInfo.widMax), (2 * kVMargin) + (fHeigth * fLines));
-
- // Make the debugging window font non-purgeable
- SetResourceNoPurge ( 'FOND', fFaceInfo.tsFont );
- SetResourceNoPurge ( 'FONT', fFaceInfo.tsFont );
-
- //scroll bars
- for ( VHSelect vhs = v; vhs <= h; ++ vhs ) {
- fSBars[vhs] = NewControl(fDebugWindowPtr, &fDebugWindowPtr->portRect, "\p", false, 0, 0, 1, scrollBarProc, 0);
- (**fSBars[vhs]).contrlRfCon = (long) this;
- }
-
- fScrollOffset.v = fScrollOffset.h = 0;
-
- //put the scroll bars in the right place
- Grown();
-
- //force an update
- UpdateEvent();
-
- //scroll to the end, in case there is some information that needs to be displayed
- SetCtlValue(fSBars[v], LONG_MAX);
- DoScrolling();
-
- }
- SetPort(savePort);
-
- return true;
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::WindowFocus(void)
- {
- SetPort(fDebugWindowPtr);
- SetOrigin(0, 0);
- ClipRect(&qd.thePort->portRect);
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::ContentFocus(void)
- { Rect r;
-
- SetPort(fDebugWindowPtr);
- SetOrigin(fScrollOffset.h, fScrollOffset.v);
- * ( Rect *) &r = * ( Rect *) & qd.thePort->portRect;
- r.right = r.right - 15;
- r.bottom = r.bottom - 15;
- ClipRect(&r);
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::ActivateEvent(short modifiers)
- { Rect r;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- WindowFocus();
-
- r = qd.thePort->portRect;
-
- if ( modifiers & 0x01 )
- {
- ShowControl ( fSBars[v] );
- ShowControl ( fSBars[h] );
- }
- else
- {
- HideControl ( fSBars[v] );
- HideControl ( fSBars[h] );
- }
-
- DrawGrowIcon(fDebugWindowPtr);
-
- SetPort(savePort);
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::Append(Ptr textBuf, long byteCount)
- {
- GrafPtr savePort;
- Rect r;
-
-
- if ( byteCount <= 0 )
- return;
-
- fDirty = fDirty && ( byteCount > 0 );
-
- if (fWrToFile)
- if (fGotRefNum)
- { long count = byteCount;
- FSWrite(fRefNum, &count, textBuf);
-
- long filePos ;
- if ( GetFPos (fRefNum, &filePos) == noErr)
- if ( SetEOF (fRefNum, filePos) == noErr )
- FlushOutputFile();
- }
-
- if (fWrToWindow)
- {
- if (fDebugWindowPtr != NULL)
- GetPort(&savePort);
-
- Boolean deleted = false;
-
- while ( byteCount > 0)
- {
- Boolean gotEOL = false;
- Ptr startPtr = textBuf;
- long startCount = byteCount;
-
- while ( (byteCount > 0) && (fPos < fPerLine) && ( !gotEOL ) )
- {
- QDByte b = * textBuf ;
- byteCount --;
- textBuf ++ ;
-
- if ( (b == 13) || ( b == 10 ) )
- { b = 13;
- gotEOL = true;
- break;
- }
- else if (b != 8)
- {
- (*fText)[fLast+fPos++] = b;
- }
- else if (fPos > 0) // Backspace -- don't backspace past beginning of line!
- {
- SetRect(&r, fEndOfText.h - fFontInfo.widMax, fEndOfText.v - fFontInfo.ascent, fEndOfText.h, fEndOfText.v + fHeigth - fFontInfo.ascent);
- fEndOfText.h = fEndOfText.h - fFontInfo.widMax;
-
- if (fDebugWindowPtr != NULL)
- {
- ContentFocus();
- EraseRect(&r);
- }
-
- fPos--;
- deleted = true;
- }
- else
- deleted = true;
- }
-
- if (!deleted && (fDebugWindowPtr != NULL))
- {
- ContentFocus();
- MoveTo(fEndOfText.h, fEndOfText.v);
- DrawText(QDPtr(startPtr), 0, (short) (startCount - byteCount - gotEOL) );
-
- PenState ps;
- GetPenState(&ps);
- fEndOfText = ps.pnLoc;
- }
-
- if ((fPos >= fPerLine) || gotEOL)
- {
- (*fLineLens)[fLast / fPerLine] = fPos; //remember # characters in this line
-
- NewLine();
- if ((byteCount > 0) && (!gotEOL))
- {
- (*fText)[fLast] = '…';
- fPos = 1;
- }
- }
- }
-
- (*fLineLens)[fLast / fPerLine] = fPos;
-
- if (fDebugWindowPtr != NULL)
- SetPort(savePort);
- }
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::FlushOutputFile(void)
- {
- if ( fWrToFile && fDirty )
- { ParamBlockRec pb;
-
- pb.ioParam.ioRefNum = fRefNum;
-
- PBFlushFileSync(&pb);
- fDirty = false;
- }
- }
-
- /***********************************|****************************************/
-
- long TTranscriptWindow::BaseLine(short ln)
- {
- return kVMargin + (ln - 1) * fHeigth;
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::DoScrolling(void)
- { Point newOffset;
- Point delta;
-
- newOffset.v = GetCtlValue(fSBars[v]);
- delta.v = fScrollOffset.v - newOffset.v;
- newOffset.h = GetCtlValue(fSBars[h]);
- delta.h = fScrollOffset.h - newOffset.h;
-
- if ((delta.h != 0) || (delta.v != 0))
- {
- ContentFocus();
-
- ScrollRect(&qd.thePort->portRect, delta.h, delta.v, fARgn);
- fScrollOffset = newOffset;
-
- InvalRgn(fARgn);
-
- UpdateEvent();
- }
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::Draw ( ) const
- {
- if ( fDebugWindowPtr)
- Draw ( fDebugWindowPtr->portRect );
- }
-
- /***********************************|****************************************/
-
-
- void TTranscriptWindow::Draw( const Rect& drawRect ) const
- {
- // PenState ps;
-
- // Expand the rect so that in includes enough extra space for a
- // line of text above and below the actual rect. Expand the
- // left and right sides of the rect to match the portRect.
- Rect clipRect = drawRect;
- clipRect.top -= fHeigth;
- clipRect.bottom += fHeigth;
-
- short y = kVMargin; //initial y corodinate
-
- long start = fFirst; //offset to first character of next line to draw
- long line = start / fPerLine; //index into fLineLens array for next line to draw; always start / fPerLine
-
- for ( long i = 1; i <= fLines; ++i )
- {
- if ( ( y >= clipRect.top ) && ( y <= clipRect.bottom ) )
- {
- MoveTo(kHMargin, y);
-
- HLock(Handle(fText));
- DrawText(QDPtr((*fText)), (short) start, (short) (*fLineLens)[line]);
- HUnlock(Handle(fText));
- }
-
- y += fHeigth;
- start = start + fPerLine;
- line++;
-
- if (start == fTotal)
- {
- start = line = 0;
- }
- }
-
- // GetPenState(&ps); //remember position of last character drawn
- // fEndOfText = ps.pnLoc;
-
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::Grown(void)
- { Rect r;
- ControlHandle anSBar;
- short newMax;
- GrafPtr savePort;
-
- GetPort(&savePort);
-
- WindowFocus();
- SetRect (&r, 0, 0, 0, 0 );
- ClipRect(&r);
-
- for (VHSelect vhs = v; vhs <= h; ++vhs )
- {
- anSBar = fSBars[vhs];
-
- r = qd.thePort->portRect;
-
- // Calculate new position of scroll bar
- (( short *) &r.top)[vhs] = (( short *) &r.top)[vhs] - 1;
- (( short *) &r.top)[gOrthogonal[vhs]] = (( short *) &r.bottom)[gOrthogonal[vhs]] - 15;
- (( short *) &r.bottom)[vhs] = (( short *) &r.bottom)[vhs] - 14;
- (( short *) &r.bottom)[gOrthogonal[vhs]] = (( short *) &r.top)[gOrthogonal[vhs]] + 16;
-
- //Move the scroll bar
- MoveControl(anSBar, r.left, r.top);
- SizeControl(anSBar, r.right-r.left, r.bottom-r.top);
-
- if ( vhs == v )
- newMax = fViewSize.v - (r.bottom - r.top);
- else
- newMax = fViewSize.h - (r.right - r.left );
-
- if (newMax < 0)
- newMax = 0;
- SetCtlMax(anSBar, newMax);
- }
-
- InvalGrowBox();
-
- DoScrolling(); //in case we are showing too much white space
-
- SetPort(savePort);
- }
-
-
- void TTranscriptWindow::InvalGrowBox(void)
- { Rect r;
-
- r = qd.thePort->portRect;
- r.top = r.bottom - 15;
- r.left = r.right - 15;
-
- InvalRect(&r);
- }
-
- /***********************************|****************************************/
-
- Boolean GetDefaultWindowInformation ( short dialogID, Boolean& visible, Rect & screenRect );
- Boolean SetDefaultWindowInformation ( DialogPtr dP, short dialogID );
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::MouseDown(short where, Point pt, short modifiers)
- { GrafPtr savePort;
-
- GetPort(&savePort);
-
- switch (where) {
- case inDrag:
- DragWindow(fDebugWindowPtr, pt, &fStdDrag);
- break;
-
- case inGrow:
- WindowFocus();
-
- long frowResult = GrowWindow(fDebugWindowPtr, pt, &fStdSize);
- if (frowResult != 0)
- { short newH = (short) (frowResult & 0xffff );
- short newV = (short) (frowResult >> 16);
-
- InvalGrowBox();
- SizeWindow(fDebugWindowPtr, newH, newV, true);
- SetDefaultWindowInformation ( fDebugWindowPtr, -1 );
-
- Grown();
- }
- break;
-
- case inGoAway:
- if (TrackGoAway(fDebugWindowPtr, pt)) {
- SetDefaultWindowInformation ( fDebugWindowPtr, -1 );
- HideWindow(fDebugWindowPtr);
- }
- break;
-
- case inContent:
- if (fDebugWindowPtr == FrontWindow())
- {
- WindowFocus();
- GlobalToLocal(&pt);
-
- ControlHandle whichControl;
- long partCode = FindControl(pt, fDebugWindowPtr, &whichControl);
- switch (partCode)
- {
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- pascal void TrackControlCallback ( ControlHandle aControl, short partCode );
- partCode = TrackControl(whichControl, pt, NewControlActionProc(ProcPtr) TrackControlCallback);
- DoScrolling();
- WindowFocus();
- break;
-
- case inThumb:
- partCode = TrackControl(whichControl, pt, NULL);
- DoScrolling();
- break;
-
- case 0:
- break;
- }
- }
- else
- SelectWindow(fDebugWindowPtr);
-
- break;
- }
-
- SetPort(savePort);
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::NewLine(void)
- { GrafPtr savePort;
- Point pt;
- Rect r;
-
- GetPort(&savePort);
-
- SetPt(&pt, kHMargin, fEndOfText.v);
-
- if ( fScrollWindowWhenTextIsAdded )
- ShowPoint(pt);
-
- fLast = fFirst;
- fPos = 0;
- (*fLineLens)[fLast / fPerLine] = fPos; //remember # characters in new line
-
- fFirst = fFirst + fPerLine;
- if (fFirst == fTotal)
- fFirst = 0;
-
- SetPt(&fEndOfText, kHMargin, (short) BaseLine(fLines) );
-
- if ( fDebugWindowPtr )
- {
- ContentFocus();
-
- SetRect(&r, kHMargin, kVMargin - fFontInfo.ascent, fViewSize.h, fEndOfText.v + fHeigth - fFontInfo.ascent);
- ScrollRect(&r, 0, -fHeigth, fARgn);
-
- InvalRgn(fARgn);
- UpdateEvent();
- }
-
- SetPort(savePort);
- }
-
- /***********************************|****************************************/
-
- OSErr TTranscriptWindow::Redirect(short vRefNum, long dirID, Str255 fileNameBase, Boolean append )
- { OSErr err;
- long x;
-
- if (fGotRefNum)
- {
- // Truncate the file to current position
- err = GetFPos(fRefNum, &x);
- err = SetEOF(fRefNum, x);
-
- if (FSClose(fRefNum) != noErr) /*??? error closing file ???*/;
- if (FlushVol(NULL, fVRefNum) != noErr) /*??? Another fine mess ???*/;
- fGotRefNum = false;
- }
-
- Str255 fileName;
- PLstrcpy ( fileName, fileNameBase );
-
- if ( PLstrlen(fileName) > 0 )
- {
- err = HCreate(vRefNum, dirID, fileName, 'R*ch', 'TEXT');
-
- if ((err == noErr) || (err == dupFNErr))
- {
- err = HOpen(vRefNum, dirID, fileName, fsRdWrPerm, &fRefNum);
- fVRefNum = vRefNum;
-
- fGotRefNum = err == noErr;
-
- if (fGotRefNum)
- if (append)
- {
- err = GetEOF(fRefNum, &x);
- err = SetFPos(fRefNum, fsFromStart, x);
- }
- else
- err = SetEOF (fRefNum, 0);
- else
- err = noErr;
- }
- }
-
- fWrToFile = ( err == noErr );
-
- return noErr;
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::Scroll(short howManyLines)
- { short val;
- GrafPtr savePort;
-
- GetPort(&savePort);
- val = GetCtlValue(fSBars[v]);
- if (((howManyLines < 0) && (val > GetCtlMin(fSBars[v]))) ||
- ((howManyLines > 0) && (val < GetCtlMax(fSBars[v]))))
- {
- SetCtlValue(fSBars[v], val + howManyLines * fHeigth);
- DoScrolling();
- }
- SetPort(savePort);
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::ShowPoint(Point pt)
- { Point minToSee;
- short deltaCd;
-
- if (fDebugWindowPtr != NULL)
- {
- WindowFocus();
-
- SetPt(&minToSee, 50, fHeigth);
-
- // the following code is actually better than writing a loop with VHSelect
- deltaCd = pt.v + minToSee.v - (qd.thePort->portRect.bottom - 15 + fScrollOffset.v);
- if (deltaCd <= 0)
- {
- deltaCd = pt.v - minToSee.v - (qd.thePort->portRect.top + fScrollOffset.v);
- if (deltaCd >= 0)
- deltaCd = 0;
- }
- SetCtlValue(fSBars[v], GetCtlValue(fSBars[v]) + deltaCd);
-
- deltaCd = pt.h + minToSee.h - (qd.thePort->portRect.right - 15 + fScrollOffset.h);
- if (deltaCd <= 0)
- {
- deltaCd = pt.h - minToSee.h - (qd.thePort->portRect.left + fScrollOffset.h);
- if (deltaCd >= 0)
- deltaCd = 0;
- }
- SetCtlValue(fSBars[h], GetCtlValue(fSBars[h]) + deltaCd);
-
- DoScrolling();
- }
- }
-
- /***********************************|****************************************/
-
- pascal void TrackControlCallback ( ControlHandle aControl, short partCode )
- {
- if (partCode != 0)
- {
- TTranscriptWindow* logWindow = (TTranscriptWindow *) (**aControl).contrlRfCon;
-
- Boolean up = (partCode == inUpButton) || (partCode == inPageUp);
- short ctlValue = GetCtlValue(aControl);
-
- // Avoid flicker in setting thumb, if (user tries to scroll past end
- if ((up && (ctlValue > GetCtlMin(aControl))) ||
- (!up && (ctlValue < GetCtlMax(aControl))))
- {
- Rect r = (*aControl)->contrlRect; // heap may compact when we call LongerSide
- VHSelect vhs = LongerSide(r); // this tells us which way we are scrolling
-
- short delta = 10;
-
- if ( logWindow )
- { WindowPtr ourWindow = logWindow->GetWindowPtr();
-
- if ((partCode == inPageUp) || (partCode == inPageDown) && ourWindow )
- if ( vhs == v )
- delta = ourWindow->portRect.bottom - ourWindow->portRect.top;
- else
- delta = ourWindow->portRect.right - ourWindow->portRect.left;
- else
- delta = logWindow->fHeigth;
- }
-
- if (up)
- delta = - delta;
-
- SetCtlValue(aControl, ctlValue + delta);
-
- if ( logWindow )
- {
- logWindow->DoScrolling();
- logWindow->WindowFocus();
- }
- }
- }
- }
-
- /***********************************|****************************************/
-
- Rect GetRegionBoundingRect ( RgnHandle rgn )
- {
- if ( rgn )
- return ( ** rgn ).rgnBBox;
- Rect r = { -32767, -32767, 32767, 32767 };
- return r;
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::UpdateEvent(void)
- { GrafPtr savePort;
- RgnHandle saveSaveVisRgn;
- RgnHandle saveVisRgn;
-
- if ((fDebugWindowPtr != NULL) &&
- (!EmptyRgn( ((WindowPeek) fDebugWindowPtr)->port.visRgn)))
- {
- GetPort(&savePort);
-
- saveSaveVisRgn = NewRgn();
- saveVisRgn = GetSaveVisRgn();
-
- CopyRgn(saveVisRgn, saveSaveVisRgn);
-
- BeginUpdate(fDebugWindowPtr);
-
- WindowFocus();
-
- EraseRect(&qd.thePort->portRect);
-
- DrawGrowIcon(fDebugWindowPtr);
- DrawControls(fDebugWindowPtr);
-
- ContentFocus();
-
- Rect updateRect = GetRegionBoundingRect ( fDebugWindowPtr->visRgn );
-
- Draw( );
-
- EndUpdate(fDebugWindowPtr);
-
- CopyRgn(saveSaveVisRgn, saveVisRgn);
- DisposeRgn(saveSaveVisRgn);
-
- SetPort(savePort);
- }
- }
-
- /***********************************|****************************************/
-
- WindowPtr TTranscriptWindow::GetWindowPtr ( ) const
- {
- return fDebugWindowPtr;
- }
-
- /***********************************|****************************************/
-
- static TTranscriptWindow* FindLogWindow ( WindowPtr wP )
- {
- for ( unsigned long index = 1; index <= gTranscriptWindowList.Count (); ++ index )
- if ( gTranscriptWindowList.Get ( index )->GetWindowPtr() == wP )
- return gTranscriptWindowList.Get ( index );
-
- return nil;
- }
-
- /***********************************|****************************************/
-
- /*
- -- Paul's Writeln routines ----------------------------------------------------------------
- */
- Boolean TTranscriptWindow::IsLogWindowEvent (const EventRecord& event )
- {
- Boolean result = false;
-
- switch ( event.what )
- {
- case mouseDown:
- {
- { WindowPtr WindowPointedTo; //window where the mouse is
- Point MouseLoc = event.where;
-
- short WindoPart = FindWindow(MouseLoc, &WindowPointedTo);
- TTranscriptWindow* logWindow = FindLogWindow ( WindowPointedTo );
-
- if ( logWindow )
- {
- if (WindowPointedTo != FrontWindow())
- SelectWindow(WindowPointedTo);
- else
- logWindow->MouseDown(WindoPart, MouseLoc, event.modifiers);
- result = true;
- }
- }
- break;
- }
-
- case activateEvt:
- { TTranscriptWindow* logWindow = FindLogWindow ( WindowPtr(event.message) );
- if ( logWindow )
- {
- logWindow->ActivateEvent ( event.modifiers );
- result = true;
- }
- break;
- }
-
- case updateEvt:
- { TTranscriptWindow* logWindow = FindLogWindow ( WindowPtr( event.message ) );
- if ( logWindow )
- {
- logWindow->UpdateEvent();
- result = true;
- }
- break;
- }
- }
-
- return result;
-
- } //Event
-
- /***********************************|****************************************/
-
-
- void TTranscriptWindow::AddEncodedText (Ptr dataPtr, long size)
- {
- for ( short index = 0; index < size; ++index )
- {
- char c = dataPtr[index];
- switch ( c )
- {
- case 0: case 128: c = 'ø'; break;
- case 8: case 136: c = 'Δ'; break;
-
- case 10: case 138: c = '◊'; break;
- case 13: case 141: c = '¬'; break;
- case 222: c = '∞'; break;
- }
- Append ( &c, 1 );
- }
- }
-
- /***********************************|****************************************/
-
- inline long IntegerMax (long a, long b )
- {
- return ( a > b ) ? a : b;
- }
-
- /***********************************|****************************************/
-
- static Str255& NumToHexStringF(long theNumber)
- { static Str255 returnStr;
-
- returnStr[0] = sprintf ((char*) &returnStr[1], "%8x", theNumber );
-
- return returnStr;
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::AddHexData (Ptr dataPtr, short dataSize )
- {
- long index ;
- Str255 result ;
- short len ;
- char byte ;
-
- if ( !dataPtr )
- {
- DebugStr ("\pNo data dump, NULL data ptr");
- return;
- }
-
- if ( dataSize <= 0 )
- {
- DebugStr ("\pNo data dump, datesize <= 0");
- return;
- }
-
- long offset = 0;
-
- while (offset < dataSize)
- {
- #if 0
- Append (
- write ( NumToHexStringF (offset), ':');
-
- // Put it into a Str255 because it's faster to add one string to the window than it is to add 16
- result = '';
- for index = 0 to 15
- do
- if offset + index < dataSize
- then
- begin
- len = length(result);
- byte = BytePtr(((long)dataPtr)+offset+index)^;
- result[len+1] = fHexStr[ ((byte) >> 4)];
- result[len+2] = fHexStr[ ((byte) & 0xF)];
- result[len+3] = ' ';
- //$PUSH*/ /*$R-*/ result[0] = ((char)(len + 3)); /*$POP
- end
- else
- begin
- result[len+1] = ' ';
- result[len+2] = ' ';
- result[len+3] = ' ';
- //$PUSH*/ /*$R-*/ result[0] = ((char)(len + 3)); /*$POP
- end();
- write (result, '| ');
-
- AddEncodedText ( Ptr(((long)dataPtr)+offset), IntegerMax(dataSize - offset, 16));
-
- offset = offset + 16;
- #endif
- }
- }
-
- /***********************************|****************************************/
-
- void TTranscriptWindow::Show (void)
- {
- if ( ! fDebugWindowPtr )
- Initialize ( );
-
- SetDefaultWindowInformation ( fDebugWindowPtr, -1 );
-
- ShowWindow (fDebugWindowPtr);
- }
-
- /***********************************|****************************************/
-